/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
 */

#ifndef TYPICAL_QP_MANAGER_H
#define TYPICAL_QP_MANAGER_H
#include <mutex>
#include <memory>
#include "adapter_hccp.h"
#include "hccl_common.h"

namespace hccl {
class TypicalQpManager {
public:
    static TypicalQpManager& GetInstance();
    HcclResult CreateQp(struct typical_qp& qpInfo);
    HcclResult ModifyQp(struct typical_qp& localQpInfo, struct typical_qp& remoteQpInfo);
    HcclResult DestroyQp(struct typical_qp& qpInfo);
    HcclResult GetQpHandleByQpn(u32 qpn, QpHandle& qpHandle);
private:
    TypicalQpManager();
    ~TypicalQpManager();
    TypicalQpManager(TypicalQpManager const&) = delete;             // Copy construct
    TypicalQpManager(TypicalQpManager&&) = delete;                  // Move construct
    TypicalQpManager& operator=(TypicalQpManager const&) = delete;  // Copy assign
    TypicalQpManager& operator=(TypicalQpManager &&) = delete;      // Move assign
    HcclResult SetQpRdmaRetryCfg(struct typical_qp& qpInfo);

private:
    RdmaHandle rdmaHandle_ = nullptr;
    const s32 QP_FLAG_RC = 0;      // flag: 0 = RC, 1= UD，其它预留
    const s32 OPBASE_QP_MODE = 2;  // 单算子模式的QP
    std::map<u32, std::pair<struct typical_qp, QpHandle>> qpMap_{};
    std::mutex qpMutex_;
};
} // namespace hccl
#endif
